package com.smartplatform.mapper;

import com.smartplatform.dto.UserDto;
import com.smartplatform.pojo.SysUserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

/**
 * @Author 咕唧
 * @Date 2022/5/26 20:15
 * @Version 1.0
 */
public interface SysUserMapper {

    @Select("select * from sys_user_info where username=#{username}")
    SysUserInfo findByName(String username);

    @Select("select * from sys_user_info where email=#{email}")
    SysUserInfo findByEmail(String email);

    @Select("select * from sys_user_info where phone=#{phone}")
    SysUserInfo findByPhone(String phone);


    @Insert("INSERT INTO sys_user_info (username,password,pwd_salt,`name`,phone,email,sex,avator,info,`type`,status,create_time,create_by,remark)" +
            " VALUES(#{username},#{password},#{pwdSalt},#{name},#{phone},#{email},#{sex},#{avator},#{info},#{type},#{status},#{createTime},#{createBy},#{remark})")
    void addUser(SysUserInfo sysUserInfo);

    @Update("UPDATE sys_user_info SET last_login= current_login, current_login=#{processDate},last_login_ip=current_login_ip,current_login_ip=#{ip} WHERE username=#{username}")
    void updateLogin(String username, Date processDate, String ip);

    void updateUser(SysUserInfo sysUserInfo);

    UserDto selectUserDto(Long id);
}
